﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class LootButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
    [SerializeField]
    private Image icon;
    [SerializeField]
    private Text text;
    private LootWindow lootWindow;
    public Image MyIcon { get => icon;  }
    public Text MyText { get => text;  }
    public Item MyLoot { get; set; }
    private void Awake()
    {
        lootWindow=GetComponentInParent<LootWindow>(); 
    }
    public void OnPointerClick(PointerEventData eventData)
    {

        if (inventoryScript.MyInstance.AddItem(MyLoot))
        {
           
            gameObject.SetActive(false);
            lootWindow.TakeLoot(MyLoot);
            UIManager.MyInstance.hideToolTip();
        }

    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        UIManager.MyInstance.showToolTip(new Vector2(1, 0), transform.position, MyLoot);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        UIManager.MyInstance.hideToolTip();
    }
}